class Node {
    public Node next;
    public int val;

    public Node(int val) {
        this.val = val;
    }

    @Override
    public String toString() {
        return "Node{" +
                "val=" + val +
                '}';
    }
}

public class LinkedList {

    private Node root;

    public void reversal(int offset, int len) {
        Node a = null;
        Node b;
        Node c;
        Node c1 = root;
        for (int i = 0; i < offset; i++) {
            a = c1;
            c1 = c1.next;
        }
        c = c1.next;
        b = c1;
        for (int i = 1; i < len; i++) {
            c1 = c.next;
            c.next = a.next;
            b.next = c1;
            a.next = c;
            c= c1;
        }
    }

    public void print() {
        Node c = root;
        for (int i = 0; i < 20 && c != null; i++) {
            System.out.print(c.val + "\t");
            c = c.next;

        }
    }

    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        linkedList.root = new Node(1);
        Node parent = linkedList.root;
        for (int i = 2; i < 10; i++) {
            parent.next = new Node(i);
            parent = parent.next;

        }

        linkedList.print();
        linkedList.reversal(2, 5);
        System.out.println();
        linkedList.print();


    }

}
